package com.ruoyi.project.module.bydpost.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.bydpost.domain.Bydpost;
import com.ruoyi.project.module.bydpost.service.IBydpostService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 岗位 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-17
 */
@Controller
@RequestMapping("/module/bydpost")
public class BydpostController extends BaseController
{
    private String prefix = "module/bydpost";
	
	@Autowired
	private IBydpostService bydpostService;
	
	@RequiresPermissions("module:bydpost:view")
	@GetMapping()
	public String bydpost()
	{
	    return prefix + "/bydpost";
	}
	
	/**
	 * 查询岗位列表
	 */
	@RequiresPermissions("module:bydpost:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Bydpost bydpost)
	{
		startPage();
        List<Bydpost> list = bydpostService.selectBydpostList(bydpost);
		return getDataTable(list);
	}

	/**
	 * 新增岗位
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 新增保存岗位
	 */
	@RequiresPermissions("module:bydpost:add")
	@Log(title = "岗位", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Bydpost bydpost)
	{		
		return toAjax(bydpostService.insertBydpost(bydpost));
	}

	/**
	 * 修改岗位
	 */
	@GetMapping("/edit/{postId}")
	public String edit(@PathVariable("postId") Integer postId, ModelMap mmap)
	{
		Bydpost bydpost = bydpostService.selectBydpostById(postId);
		mmap.put("bydpost", bydpost);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存岗位
	 */
	@RequiresPermissions("module:bydpost:edit")
	@Log(title = "岗位", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Bydpost bydpost)
	{		
		return toAjax(bydpostService.updateBydpost(bydpost));
	}
	
	/**
	 * 删除岗位
	 */
	@RequiresPermissions("module:bydpost:remove")
	@Log(title = "岗位", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bydpostService.deleteBydpostByIds(ids));
	}
	
}
